<?php
require 'include/global.php';
require_once 'include/train_db.php';
include("include/HOP.php");

$smarty->compile_check = true;

/**************************************************
Accept the POST values and place them in variables
**************************************************/

$bill_city = $_POST["billTo_city"];
$bill_company = $_POST["billTo_company"];
$bill_country = $_POST["billTo_country"];
$bill_email = $_POST["billTo_email"];
$customer_firstname = $_POST["billTo_firstName"];
$customer_lastname = $_POST["billTo_lastName"];
$bill_phone = $_POST["billTo_phoneNumber"];
$bill_zip = $_POST["billTo_postalCode"];
$bill_state = $_POST["billTo_state"];
$bill_address1 = $_POST["billTo_street1"];
$bill_address2 = $_POST["billTo_street2"];
$amount = $_POST["ccAuthReply_amount"];
$auth_code = $_POST["ccAuthReply_authorizationCode"];
$auth_time = $_POST["ccAuthReply_authorizedDateTime"];
$avs_code = $_POST["ccAuthReply_avsCode"];
$avs_raw = $_POST["ccAuthReply_avsCodeRaw"];
$cvv_code = $_POST["ccAuthReply_cvCode"];
$cvv_raw = $_POST["ccAuthReply_cvCodeRaw"];
$factor_code = $_POST["ccAuthReply_factorCode"];
$processor_response = $_POST["ccAuthReply_processorResponse"];
$reason_code = $_POST["ccAuthReply_reasonCode"];
$comments = $_POST["comments"];
$merchant_id = $_POST["merchantID"];
$order_amount = $_POST["orderAmount"];
$order_number = $_POST["orderNumber"];
$public_signature = $_POST["orderNumber_publicSignature"];
$transaction_type = $_POST["orderPage_transactionType"];
$reason_code_simple = $_POST["reasonCode"];
$request_id = $_POST["requestID"];
$decision = $_POST["decision"];
$ship_city = $_POST["shipTo_city"];
$ship_company = $_POST["shipTo_company"];
$ship_country = $_POST["shipTo_country"];
$ship_firstname = $_POST["shipTo_firstName"];
$ship_lastname = $_POST["shipTo_lastName"];
$ship_zip = $_POST["shipTo_zip"];
$ship_state = $_POST["shipTo_state"];
$ship_address1 = $_POST["shipTo_street1"];
$ship_address2 = $_POST["shipTo_street2"];
$tax_amount = $_POST["taxAmount"];

$my_custom_field = $_POST["my_custom_field"];

$nm = explode("|",$my_custom_field);

if($reason_code_simple=="100"&&$decision=="ACCEPT"&&$_SESSION[checked]!='1'){
	 $_SESSION[checked] = "1";
	 $cyber_utype = $nm[1];
	 $cyber_uid   = $nm[0];
	 //exit;
	 switch($cyber_utype){
	 case recruiter:
		 $DB->query("UPDATE pa_recuiter SET `rc_deadline`='0',`rc_status`=2  WHERE rc_id = '".$cyber_uid."'");
		 break;
	 case employer:
		 $DB->query("UPDATE pa_employer SET `ep_deadline`='0',`ep_status`=1 WHERE ep_id = '".$cyber_uid."'");
		 break;
	 case candidate:
		  $DB->query("UPDATE pa_candidates SET `js_deadline`='0',`js_status`=1 WHERE js_id = '".$cyber_uid."'");
		 break;
	 case advisor:
		  $DB->query("UPDATE pa_advisory SET `ad_deadline`= '0',`ad_status`=1 WHERE ad_id = '".$cyber_uid."'");
		 break;
	 }
    $sql = "INSERT INTO `pa_order` ( `pa_id` , `pa_uid` , `pa_utype` , `pa_uname` , `pa_price` , `pa_charged` ) 
				VALUES (
				'".$order_number."', '".$cyber_uid."', '".$cyber_utype."', '', '".$amount."', '1'
				);";
    //echo $sql;
	$DB->query($sql);
	$title = "Successful Order";
    $reg   = "Your purchase has been successfully processed! Thank you!";
}

if($reason_code_simple=="200"){
  $title = "Order to Review";
  $reg   = "The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the Address Verification Service (AVS) check.";
}
if($reason_code_simple=="201"){
  $title = "Order to Review";
  $reg   = "The issuing bank has questions about the request. You cannot receive an authorization code in the API reply, but you may receive one verbally by calling the bank.";
}
if($reason_code_simple=="230"){
  $title = "Order to Review";
  $reg   = "The credit card was accepted by the bank but refused by CyberSource because it did not pass the card verification number check. The card verification result is N.";
}
if($reason_code_simple=="520"){
  $title = "Order to Review";
  $reg   = "The authorization request was approved by the issuing bank but declined by CyberSource based on your Smart Authorization settings.";
}

if($reason_code_simple=="203"||$reason_code_simple=="102"){
  $title = "Failed Order";
  $reg   = "Most transactions that cannot be accepted are rejected, and the your receives the reply page for a failed order.";
}

if($_SESSION[checked]==1){  
    $title = "Successful Order";
    $reg   = 'Thank you for your order!  Your account status will be updated shortly.  To access your updated account, please sign out and then sign in again. <input type="button" value="Sign Out" onclick="window.location.href=\'index.php\'">';
}

$smarty->assign("title",$title);
$smarty->assign("reg",$reg);
$smarty->display('header.tpl');
$smarty->display('left.tpl');
$smarty->display('reg.tpl');
$smarty->display('right.tpl');
$smarty->display('footer.tpl');


?>